/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication3;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URLEncoder;

/**
 *
 * @author dimitri
 */
public class JavaApplication3 {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // Construct data
            /*String data = URLEncoder.encode("key1", "UTF-8") + "=" + URLEncoder.encode("value1", "UTF-8");
            data += "&" + URLEncoder.encode("key2", "UTF-8") + "=" + URLEncoder.encode("value2", "UTF-8");
*/
            
            // Create a socket to the host
            String hostname = "bttracker.debian.org";
            int port = 6969;
            InetAddress addr = InetAddress.getByName(hostname);
            Socket socket = new Socket(addr, port);

            // Send header
            String path = "/announce?info_hash=x%60%a0tkm%c4%d0%be%11%5b%c9%7d%bdA%3b%3d%27%84%01&peer_id=-TR2130-n12r35yy9y17&port=51413&uploaded=0&downloaded=0&left=679477248&numwant=80&key=duzwhmd8&compact=1&supportcrypto=0&event=started";
            //String path = "/announce?chtugulu=1";
            BufferedWriter wr = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream(), "UTF8"));
            wr.write("GET " + path + " HTTP/1.1\r\n");
            //wr.write("Content-Length: " + path.length() + "\r\n");
            //wr.write("Content-Type: application/x-www-form-urlencoded\r\n");
            wr.write("Connection: close\r\n");
            wr.write("\r\n");

            // Send data
            //wr.write(data);
            wr.flush();

            // Get response
            BufferedReader rd = new BufferedReader(new InputStreamReader(socket.getInputStream()));
            String line;
            while ((line = rd.readLine()) != null) {
                System.out.println(line);
            }
            wr.close();
            rd.close();
        } catch (Exception e) {
        }
    }
}
